<% content_for :head do %>
  <%= javascript_include_tag "https://www.google.com/jsapi" %>
  <%= javascript_include_tag "show_user_entries" %>
<% end %>

<h1>Listing your data. Only for your and my eyes.</h1>

<div id='battery_events_hourly_cluster_chart'></div>

<div id='charging_or_not_by_time_chart'></div>

<div id='not_charging_duration_by_time_chart'></div>

<div id='connectivity_events_hourly_cluster_chart'></div>

<div id='connected_WiFi_or_not_by_time_chart'></div>

<div id='no_WiFi_connectivity_duration_by_time_chart'></div>

<div id='connected_3G_or_not_by_time_chart'></div>

<div id='no_3G_connectivity_duration_by_time_chart'></div>

<table class="box-table">
  	<thead>
	  	<tr>
		    <th scope="col">Battery Events</th>
			<th scope="col">Power Connections</th>
			<th scope="col">via USB</th>
			<th scope="col">via AC</th>
			<th scope="col">Power Disconnections</th>
		    <th scope="col">Connectivity Events</th>
		    <th scope="col">Net Connections</th>
		    <th scope="col">via Wi-Fi</th>
		    <th scope="col">via Mobile</th>
		    <th scope="col">Net Disconnections</th>
    	    <th scope="col">OS Events</th>
		    <th scope="col">OS Shutdown</th>
		    <th scope="col">OS Boot</th>
		    <th scope="col">Total Events</th>
		    <th scope="col">Total Days</th>
		</tr>
	</thead>

	<% if !@monitor_entries.empty? %>
		<tbody>
	    	<tr>
			    <td><%= MonitorEntry.get_user_events_quantity_by_log_class @monitor_entries.first.user_uuid, MonitorEntry.BATTERY_ENTRY, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_events_quantity_by_log_class_and_status @monitor_entries.first.user_uuid, MonitorEntry.BATTERY_ENTRY, MonitorEntry.POWER_CONNECTED, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_battery_events_quantity_by_type @monitor_entries.first.user_uuid, MonitorEntry.POWER_TYPE_USB, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_battery_events_quantity_by_type @monitor_entries.first.user_uuid, MonitorEntry.POWER_TYPE_AC, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_events_quantity_by_log_class_and_status @monitor_entries.first.user_uuid, MonitorEntry.BATTERY_ENTRY, MonitorEntry.POWER_DISCONNECTED, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_events_quantity_by_log_class @monitor_entries.first.user_uuid, MonitorEntry.CONNECTIVITY_ENTRY, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_events_quantity_by_log_class_and_status @monitor_entries.first.user_uuid, MonitorEntry.CONNECTIVITY_ENTRY, MonitorEntry.NET_CONNECTED, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_connectivity_events_quantity_by_type @monitor_entries.first.user_uuid, MonitorEntry.NET_TYPE_WIFI, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_connectivity_events_quantity_by_type @monitor_entries.first.user_uuid, MonitorEntry.NET_TYPE_MOBILE, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_events_quantity_by_log_class_and_status @monitor_entries.first.user_uuid, MonitorEntry.CONNECTIVITY_ENTRY, MonitorEntry.NET_DISCONNECTED, params[:days_ago] %></td>
	    	    <td><%= MonitorEntry.get_user_events_quantity_by_log_class @monitor_entries.first.user_uuid, MonitorEntry.OS_ENTRY, params[:days_ago] %></td>
			   	<td><%= MonitorEntry.get_user_events_quantity_by_log_class_and_status @monitor_entries.first.user_uuid, MonitorEntry.OS_ENTRY, MonitorEntry.OS_SHUTDOWN, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_events_quantity_by_log_class_and_status @monitor_entries.first.user_uuid, MonitorEntry.OS_ENTRY, MonitorEntry.OS_BOOT, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_events_quantity @monitor_entries.first.user_uuid, params[:days_ago] %></td>
			    <td><%= MonitorEntry.get_user_participation_total_days @monitor_entries.first.user_uuid %></td>
		  	</tr>
		</tbody>
	<% end %>
</table>

<table id="sortable-list" class="box-table">
  <thead>
	  <tr>
	    <th scope="col">Date (with timezone)</th>
	    <th data-sort="string" scope="col">Log Class</th>
	    <th data-sort="string" scope="col">Status</th>
	    <th data-sort="string" scope="col">Type</th>
	  </tr>
  </thead>

	<tbody>
	<% @monitor_entries.each do |monitor_entry| %>
	  <tr>
	    <td><%= monitor_entry.date + (monitor_entry.time_zone/3600000).hours %><%=monitor_entry.time_zone/3600000%></td>
	    <td>
	    	<%= get_log_class_desc monitor_entry.log_class %>
		</td>
	    <td>
	    	<% if monitor_entry.log_class == MonitorEntry.BATTERY_ENTRY %> 
	    		<%= get_status_desc_for_battery monitor_entry.status %> 
	    	<% elsif monitor_entry.log_class == MonitorEntry.CONNECTIVITY_ENTRY %>
	    		<%= get_status_desc_for_connectivity monitor_entry.status %> 
	    	<% else %>
	    		<%= get_status_desc_for_os monitor_entry.status %> 
	    	<% end %>
    	</td>
    	<td>
	    	<% if monitor_entry.log_class == MonitorEntry.BATTERY_ENTRY %> 
	    		<%= get_type_desc_for_battery monitor_entry.type_ %> 
	    	<% else %>
	    		<%= get_type_desc_for_connectivity monitor_entry.type_ %> 
	    	<% end %>
    	</td>
	  </tr>
	<% end %>
	</tbody>
</table>
<%= paginate @monitor_entries %>
